﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace INF7GEN
{
    /// <summary>
    /// Acts as a hub for a single game.
    /// </summary>
    [Serializable()]
    public class GlobalStates : ISerializable
    {
        private UInt16 inf7genVersion = 3;//this is stored in each save file, allowing each serialization to be custom tailored for each version
        private String authorName = "";
        private String projectName = "";
        private String storyHeadline = "";//text listed at start of story
        private List<Thing> things = new List<Thing>();
        private List<UserCommand> userCommands = new List<UserCommand>();
        private List<Action> actions = new List<Action>();
        private List<Room> rooms = new List<Room>();
        public static string[] type = {//thing types
                                          "thing",
                                          "person",
                                          "animal",
                                          "woman",
                                          "man",
                                          "boy",
                                          "girl"
                                      };
        private Extensions extensions = new Extensions();//contains all extension data


        public GlobalStates()
        {
        }


        //--------------------------------------------------------------------
        //Serialization-------------------------------------------------------
        public GlobalStates(SerializationInfo info, StreamingContext ctxt)
        {
            this.Inf7genVersion = (UInt16)info.GetValue("Inf7genVersion", typeof(UInt16));
            
            switch (this.Inf7genVersion)
            {
                case 3://Alpha 3-release date unknown
                    this.Things = (List<Thing>)info.GetValue("Things", typeof(List<Thing>));
                    this.AuthorName = (String)info.GetValue("AuthorName", typeof(String));
                    this.ProjectName = (String)info.GetValue("ProjectName", typeof(String));
                    this.StoryHeadline = (String)info.GetValue("StoryHeadline", typeof(String));
                    this.UserCommands = (List<UserCommand>)info.GetValue("UserCommands", typeof(List<UserCommand>));
                    this.actions = (List<Action>)info.GetValue("Actions", typeof(List<Action>));
                    this.Rooms = (List<Room>)info.GetValue("Rooms", typeof(List<Room>));
                    this.extensions = (Extensions)info.GetValue("Extensions", typeof(Extensions));
                    break;
                default:
                    break;
            }

            
            
        }
        
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Inf7genVersion", this.Inf7genVersion);
            info.AddValue("Things", this.Things);
            info.AddValue("AuthorName", this.AuthorName);
            info.AddValue("ProjectName", this.ProjectName);
            info.AddValue("StoryHeadline", this.StoryHeadline);
            info.AddValue("UserCommands", this.UserCommands);
            info.AddValue("Actions", this.actions);
            info.AddValue("Rooms", this.Rooms);
            info.AddValue("Extensions", this.extensions);
        }
        //-------------------------------------------------------------------



        /// <summary>
        /// re_initializes things list.
        /// </summary>
        public void resetThings()
        {
            this.things = new List<Thing>();
        }

        /// <summary>
        /// re_initializes userCommands list.
        /// </summary>
        public void resetUserCommands()
        {
            this.userCommands = new List<UserCommand>();
        }

        /// <summary>
        /// re_initializes actions list.
        /// </summary>
        public void resetActions()
        {
            this.actions = new List<Action>();
        }

        /// <summary>
        /// re_initializes Rooms list.
        /// </summary>
        public void resetRooms()
        {
            this.Rooms = new List<Room>();
        }

        /// <summary>
        /// re_initializes Extensions.
        /// </summary>
        public void resetExtensions()
        {
            this.extensions = new Extensions();
        }

        
        public UInt16 Inf7genVersion
        {
            get { return this.inf7genVersion; }
            set { this.inf7genVersion = value; }
        }

        public List<Thing> Things
        {
            get { return this.things; }
            set { this.things = value; }
        }

        public List<Room> Rooms
        {
            get { return this.rooms; }
            set { this.rooms = value; }
        }

        public List<UserCommand> UserCommands
        {
            get { return this.userCommands; }
            set { this.userCommands = value; }
        }

        public List<Action> Actions
        {
            get { return this.actions; }
            set { this.actions = value; }
        }

        public string AuthorName
        {
            get { return this.authorName; }
            set { this.authorName = value; }
        }

        public string StoryHeadline
        {
            get { return this.storyHeadline; }
            set { this.storyHeadline = value; }
        }

        public string ProjectName
        {
            get { return this.projectName; }
            set { this.projectName = value; }
        }

        public Extensions Extensions
        {
            get { return this.extensions; }
            set { this.extensions = value; }
        }

    }


    

    
    
}
